<?php
// 处理静态文件和特殊文件请求 - 临时解决方案
$requestUri = $_SERVER['REQUEST_URI'] ?? '';
$pathInfo = pathinfo($requestUri);

// 处理robots.txt
if ($requestUri === '/robots.txt') {
    if (file_exists('robots.txt')) {
        header('Content-Type: text/plain; charset=utf-8');
        header('Cache-Control: public, max-age=86400');
        readfile('robots.txt');
        exit;
    }
}

// 处理sitemap.xml
if ($requestUri === '/sitemap.xml') {
    // 设置正确的路径和包含
    define('IN_SITEMAP', true);
    require_once 'config/config.php';
    require_once 'includes/database.php';

    // 设置响应头
    header('Content-Type: application/xml; charset=utf-8');
    header('Cache-Control: public, max-age=3600'); // 缓存1小时

    // 初始化数据库
    $db = new Database();
    $categories = $db->getCategories();
    $allNavigations = [];

    // 获取所有导航数据
    foreach ($categories as $category) {
        $navs = $db->getNavigations($category['id']);
        $allNavigations[$category['id']] = $navs;
    }

    // 获取网站设置
    $settings = $db->getSettings();
    $siteTitle = $settings['site_title'] ?? SITE_TITLE;
    $siteUrl = SITE_URL;

    // 开始XML输出
    echo '<?xml version="1.0" encoding="UTF-8"?>';
    ?>
    <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
            xmlns:xhtml="http://www.w3.org/1999/xhtml"
            xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">

        <!-- 首页 -->
        <url>
            <loc><?php echo htmlspecialchars($siteUrl); ?></loc>
            <lastmod><?php echo date('Y-m-d'); ?></lastmod>
            <changefreq>weekly</changefreq>
            <priority>1.0</priority>
            <xhtml:link rel="alternate" hreflang="zh-CN" href="<?php echo htmlspecialchars($siteUrl); ?>"/>
        </url>

        <!-- 分类页面 -->
        <?php foreach ($categories as $category): ?>
        <url>
            <loc><?php echo htmlspecialchars($siteUrl . '#' . strtolower(str_replace([' ', '&', ' ', '，'], '-', $category['name']))); ?></loc>
            <lastmod><?php echo htmlspecialchars($category['updated_at']); ?></lastmod>
            <changefreq>weekly</changefreq>
            <priority>0.8</priority>
            <xhtml:link rel="alternate" hreflang="zh-CN" href="<?php echo htmlspecialchars($siteUrl . '#' . strtolower(str_replace([' ', '&', ' ', '，'], '-', $category['name']))); ?>"/>
        </url>
        <?php endforeach; ?>

        <!-- 导航网站 -->
        <?php foreach ($allNavigations as $categoryId => $navigations): ?>
            <?php foreach ($navigations as $nav): ?>
            <url>
                <loc><?php echo htmlspecialchars($nav['url']); ?></loc>
                <lastmod><?php echo htmlspecialchars($nav['updated_at']); ?></lastmod>
                <changefreq>monthly</changefreq>
                <priority>0.6</priority>

                <!-- 如果有图片，添加图片信息 -->
                <?php if (!empty($nav['icon']) && $nav['icon_type'] === 'url'): ?>
                <image:image>
                    <image:loc><?php echo htmlspecialchars($siteUrl . ltrim($nav['icon'], './')); ?></image:loc>
                    <image:title><?php echo htmlspecialchars($nav['name']); ?> Logo</image:title>
                    <image:caption><?php echo htmlspecialchars($nav['description'] ?? $nav['name'] . '网站logo'); ?></image:caption>
                </image:image>
                <?php endif; ?>

                <!-- 外部链接提示 -->
                <xhtml:link rel="alternate" hreflang="en" href="<?php echo htmlspecialchars($nav['url']); ?>"/>
            </url>
            <?php endforeach; ?>
        <?php endforeach; ?>

    </urlset>
    <?php exit;
}

// 处理其他静态文件
$staticExtensions = ['css', 'js', 'png', 'jpg', 'jpeg', 'gif', 'ico', 'svg', 'woff', 'woff2', 'ttf', 'eot'];

if (isset($pathInfo['extension']) && in_array(strtolower($pathInfo['extension']), $staticExtensions)) {
    $filePath = ltrim($requestUri, '/');

    if (file_exists($filePath)) {
        $extension = strtolower($pathInfo['extension']);
        $contentTypes = [
            'css' => 'text/css',
            'js' => 'application/javascript',
            'png' => 'image/png',
            'jpg' => 'image/jpeg',
            'jpeg' => 'image/jpeg',
            'gif' => 'image/gif',
            'ico' => 'image/x-icon',
            'svg' => 'image/svg+xml',
            'woff' => 'font/woff',
            'woff2' => 'font/woff2',
            'ttf' => 'font/ttf',
            'eot' => 'application/vnd.ms-fontobject'
        ];

        if (isset($contentTypes[$extension])) {
            header('Content-Type: ' . $contentTypes[$extension]);
        }

        header('Cache-Control: public, max-age=86400');
        header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + 86400));

        readfile($filePath);
        exit;
    }

    http_response_code(404);
    echo 'Static file not found';
    exit;
}

require_once 'config/config.php';
require_once 'includes/database.php';

// 设置SEO优化的响应头
setSEOResponseHeaders();

// 初始化数据库
$db = new Database();

// 获取系统设置，优先使用数据库设置
$settings = $db->getSettings();
$siteTitle = $settings['site_title'] ?? SITE_TITLE;
$siteDescription = $settings['site_description'] ?? SITE_DESCRIPTION;
$siteKeywords = $settings['site_keywords'] ?? SITE_KEYWORDS;
$faviconPath = $settings['favicon_path'] ?? 'assets/images/favicon.ico';

// 获取分类和导航数据
$categories = $db->getCategories();

// 按排序序号升序排列分类
usort($categories, function($a, $b) {
    return ($a['sort'] ?? 0) - ($b['sort'] ?? 0);
});

$navigations = [];
$tags = [];
foreach ($categories as $category) {
    $navigations[$category['id']] = $db->getNavigations($category['id']);
    $tags[$category['id']] = $db->getTags($category['id']);
}

// 去重导航（因为一个导航可能属于多个分类）
$allNavigations = $db->getNavigations();
$displayedNavigations = []; // 记录已显示的导航ID

// 计算总导航数（用于SEO）
$totalNavigations = count($allNavigations);

// 获取常用导航
$favoriteNavigations = $db->getFavoriteNavigations(8); // 限制显示8个常用导航

/**
 * 将display_style转换为对应的CSS类名
 * @param string $displayStyle display_style值（如STYLE_1, STYLE_2等）
 * @return string 对应的CSS类名（如nav-style-1, nav-style-2等）
 */
function getDisplayStyleClass($displayStyle) {
    $styleMap = [
        'STYLE_1' => 'nav-style-1',
        'STYLE_2' => 'nav-style-2',
        'STYLE_3' => 'nav-style-3',
        'STYLE_4' => 'nav-style-4',
        'STYLE_5' => 'nav-style-5'
    ];

    return $styleMap[$displayStyle] ?? 'nav-style-1'; // 默认返回nav-style-1
}

/**
 * 判断链接是否需要添加nofollow属性
 * @param string $url 链接URL
 * @return string rel属性值
 */
function getLinkRelAttribute($url) {
    // 如果链接是ilovefree.com域名，不添加nofollow
    $allowedDomains = ['ilovefree.com', 'www.ilovefree.com', 'localhost'];
    $urlParts = parse_url($url);

    if (isset($urlParts['host'])) {
        foreach ($allowedDomains as $domain) {
            if (stripos($urlParts['host'], $domain) !== false) {
                return 'noopener noreferrer'; // 内部链接，不加nofollow
            }
        }
    }

    // 外部链接添加nofollow
    return 'noopener noreferrer nofollow';
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title><?php echo htmlspecialchars($siteTitle); ?></title>
    <meta name="description" content="<?php echo htmlspecialchars($siteDescription); ?>">
    <meta name="keywords" content="<?php echo htmlspecialchars($siteKeywords); ?>">

    <!-- SEO优化：基础Meta标签 -->
    <meta name="robots" content="index, follow">
    <meta name="googlebot" content="index, follow">
    <meta name="author" content="<?php echo htmlspecialchars($siteTitle); ?>">
    <meta name="publisher" content="<?php echo htmlspecialchars($siteTitle); ?>">
    <meta name="language" content="zh-CN">
    <meta name="generator" content="PHP Navigation System">
    <meta name="rating" content="general">
    <meta name="distribution" content="global">
    <meta name="revisit-after" content="7 days">

    <!-- Canonical标签 - 防止重复内容 -->
    <link rel="canonical" href="<?php echo SITE_URL; ?>">

    <!-- Open Graph / 社交媒体 -->
    <meta property="og:type" content="website">
    <meta property="og:title" content="<?php echo htmlspecialchars($siteTitle); ?>">
    <meta property="og:description" content="<?php echo htmlspecialchars($siteDescription); ?>">
    <meta property="og:url" content="<?php echo SITE_URL; ?>">
    <meta property="og:site_name" content="<?php echo htmlspecialchars($siteTitle); ?>">
    <meta property="og:locale" content="zh_CN">

    <!-- Twitter Cards -->
    <meta name="twitter:card" content="summary_large_image">
    <meta name="twitter:title" content="<?php echo htmlspecialchars($siteTitle); ?>">
    <meta name="twitter:description" content="<?php echo htmlspecialchars($siteDescription); ?>">
    <meta name="twitter:site" content="@<?php echo str_replace([' ', ' '], '', $siteTitle); ?>">
    <meta name="twitter:creator" content="@<?php echo str_replace([' ', ' '], '', $siteTitle); ?>">
    <meta name="twitter:image" content="<?php echo SITE_URL . asset('images/favicon.png'); ?>">

    <!-- 移动端和浏览器优化 -->
    <meta name="format-detection" content="telephone=no">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="default">
    <meta name="apple-mobile-web-app-title" content="<?php echo htmlspecialchars($siteTitle); ?>">
    <meta name="application-name" content="<?php echo htmlspecialchars($siteTitle); ?>">
    <meta name="msapplication-TileColor" content="#667eea">
    <meta name="theme-color" content="#667eea">
    
    <!-- 性能优化：关键资源预加载 -->
    <link rel="preload" href="<?php echo asset('css/style.css'); ?>" as="style">
    <link rel="preload" href="<?php echo asset('js/config.js'); ?>" as="script">
    <link rel="preload" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" as="style" crossorigin="anonymous">
    <link rel="dns-prefetch" href="//cdnjs.cloudflare.com">
    
    <!-- 样式文件 -->
    <link rel="stylesheet" href="<?php echo asset('css/style.css'); ?>">

    <!-- ilovefree 搜索样式 -->
    <link rel="stylesheet" href="<?php echo asset('css/pickfree-search.css'); ?>">

    <!-- ilovefree 样式迁移系统 -->
    <link rel="stylesheet" href="<?php echo asset('css/ilovefree-migration.css'); ?>">
    <link rel="stylesheet" href="<?php echo asset('css/enhanced-layout.css'); ?>">
    <link rel="stylesheet" href="<?php echo asset('css/fontawesome-icons.css'); ?>">

    <!-- 粘性导航栏样式 -->
    <link rel="stylesheet" href="<?php echo asset('css/sticky-nav.css'); ?>">

    <!-- Font Awesome 图标库 - 异步加载优化 -->
    <link rel="preload" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" as="style" onload="this.onload=null;this.rel='stylesheet'" integrity="sha512-iecdLmaskl7CVkqkXNQ/ZH/XLlvWZOJyj7Yy7tcenmpD1ypASozpmT/E0iPtmFIB46ZmdtAc9eNBvH0H/ZpiBw==" crossorigin="anonymous" referrerpolicy="no-referrer">
    <noscript><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" integrity="sha512-iecdLmaskl7CVkqkXNQ/ZH/XLlvWZOJyj7Yy7tcenmpD1ypASozpmT/E0iPtmFIB46ZmdtAc9eNBvH0H/ZpiBw==" crossorigin="anonymous" referrerpolicy="no-referrer"></noscript>

    <!-- JavaScript配置文件 - 异步加载 -->
    <script src="<?php echo asset('js/config.js'); ?>" defer></script>
    
    <!-- 网站图标 -->
    <link rel="icon" type="image/x-icon" href="<?php echo getUrl($faviconPath); ?>">
    <link rel="apple-touch-icon" href="<?php echo asset('images/apple-touch-icon.png'); ?>">
    
    <!-- 可点击的网站图标 -->
    <div id="favicon-link-container" style="position: absolute; top: 10px; left: 10px; z-index: 9999;">
        <?php if (!empty($settings['favicon_link'])): ?>
            <a href="<?php echo htmlspecialchars($settings['favicon_link']); ?>" title="点击访问" target="_blank" style="display: inline-block;">
                <img src="<?php echo getUrl($faviconPath); ?>" alt="网站图标" style="width: 32px; height: 32px; border-radius: 4px; cursor: pointer;">
            </a>
        <?php else: ?>
            <a href="<?php echo SITE_URL; ?>" title="返回首页" style="display: inline-block;">
                <img src="<?php echo getUrl($faviconPath); ?>" alt="网站图标" style="width: 32px; height: 32px; border-radius: 4px; cursor: pointer;">
            </a>
        <?php endif; ?>
    </div>
    
    <!-- Open Graph / Social Media -->
    <meta property="og:type" content="website">
    <meta property="og:title" content="<?php echo htmlspecialchars($siteTitle); ?>">
    <meta property="og:description" content="<?php echo htmlspecialchars($siteDescription); ?>">
    <meta property="og:url" content="<?php echo SITE_URL; ?>">
    
    <!-- Apple Web App -->
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="default">
    <meta name="apple-mobile-web-app-title" content="<?php echo htmlspecialchars($siteTitle); ?>">

    <!-- 增强SEO结构化数据 (JSON-LD) -->
    <script type="application/ld+json">
    {
        "@context": "https://schema.org",
        "@type": "WebSite",
        "@id": "<?php echo SITE_URL; ?>#website",
        "name": "<?php echo htmlspecialchars($siteTitle); ?>",
        "url": "<?php echo SITE_URL; ?>",
        "description": "<?php echo htmlspecialchars($siteDescription); ?>",
        "inLanguage": "zh-CN",
        "keywords": "<?php echo htmlspecialchars($siteKeywords); ?>",
        "genre": ["设计资源", "开发工具", "免费素材", "导航网站"],
        "audience": {
            "@type": "Audience",
            "audienceType": "设计师,开发者,独立开发者"
        },
        "potentialAction": {
            "@type": "SearchAction",
            "target": {
                "@type": "EntryPoint",
                "urlTemplate": "https://www.baidu.com/s?wd={search_term_string}"
            },
            "query-input": "required name=search_term_string"
        },
        "publisher": {
            "@type": "Organization",
            "@id": "<?php echo SITE_URL; ?>#organization",
            "name": "<?php echo htmlspecialchars($siteTitle); ?>",
            "url": "<?php echo SITE_URL; ?>",
            "description": "<?php echo htmlspecialchars($siteDescription); ?>",
            "logo": {
                "@type": "ImageObject",
                "url": "<?php echo getUrl($faviconPath); ?>",
                "width": 32,
                "height": 32
            },
            "sameAs": [],
            "contactPoint": {
                "@type": "ContactPoint",
                "contactType": "customer service",
                "availableLanguage": "zh-CN"
            }
        },
        "mainEntity": {
            "@type": "ItemList",
            "name": "免费资源导航列表",
            "description": "为设计师和开发者精选的免费资源集合",
            "numberOfItems": <?php echo $totalNavigations; ?>,
            "itemListElement": [
                <?php
                $structuredItems = [];
                $itemCount = 0;
                foreach ($categories as $category) {
                    if (!empty($navigations[$category['id']])) {
                        foreach ($navigations[$category['id']] as $nav) {
                            if ($itemCount < 10) { // 限制显示前10个，避免JSON过大
                                $structuredItems[] = [
                                    '@type' => 'ListItem',
                                    'position' => $itemCount + 1,
                                    'item' => [
                                        '@type' => 'WebSite',
                                        'name' => $nav['name'],
                                        'description' => $nav['description'] ?? $nav['name'],
                                        'url' => $nav['url'],
                                        'category' => $category['name']
                                    ]
                                ];
                                $itemCount++;
                            }
                        }
                    }
                }
                echo json_encode($structuredItems, JSON_UNESCAPED_UNICODE);
                ?>
            ]
        }
    }
    </script>

    <!-- 组织架构数据 -->
    <script type="application/ld+json">
    {
        "@context": "https://schema.org",
        "@type": "Organization",
        "@id": "<?php echo SITE_URL; ?>#organization",
        "name": "<?php echo htmlspecialchars($siteTitle); ?>",
        "url": "<?php echo SITE_URL; ?>",
        "description": "<?php echo htmlspecialchars($siteDescription); ?>",
        "logo": {
            "@type": "ImageObject",
            "url": "<?php echo getUrl($faviconPath); ?>"
        },
        "sameAs": [],
        "contactPoint": {
            "@type": "ContactPoint",
            "contactType": "customer service"
        }
    }
    </script>

    <!-- 面包屑导航架构 -->
    <script type="application/ld+json">
    {
        "@context": "https://schema.org",
        "@type": "BreadcrumbList",
        "itemListElement": [
            {
                "@type": "ListItem",
                "position": 1,
                "name": "首页",
                "item": "<?php echo SITE_URL; ?>"
            },
            {
                "@type": "ListItem",
                "position": 2,
                "name": "免费素材导航",
                "item": "<?php echo SITE_URL; ?>"
            }
        ]
    }
    </script>

    <!-- 分类和导航项目结构化数据 -->
    <?php if (!empty($categories)): ?>
    <?php foreach ($categories as $index => $category): ?>
    <script type="application/ld+json">
    {
        "@context": "https://schema.org",
        "@type": "CollectionPage",
        "@id": "<?php echo SITE_URL; ?>#category-<?php echo $category['id']; ?>",
        "name": "<?php echo htmlspecialchars($category['name']); ?>",
        "description": "收录优质<?php echo htmlspecialchars($category['name']); ?>网站，为设计师和开发者提供精选资源导航。",
        "url": "<?php echo SITE_URL; ?>#<?php echo generateSEOFriendlyUrl($category['name']); ?>",
        "isPartOf": {
            "@type": "WebSite",
            "@id": "<?php echo SITE_URL; ?>#website",
            "name": "<?php echo htmlspecialchars($siteTitle); ?>"
        },
        "numberOfItems": <?php echo count($navigations[$category['id']] ?? []); ?>,
        "mainEntity": {
            "@type": "ItemList",
            "numberOfItems": <?php echo count($navigations[$category['id']] ?? []); ?>,
            "itemListElement": [
                <?php
                $navItems = $navigations[$category['id']] ?? [];
                $itemElements = [];
                foreach ($navItems as $navIndex => $nav):
                    $itemElements[] = [
                        '@type' => 'ListItem',
                        'position' => $navIndex + 1,
                        'name' => $nav['name'],
                        'description' => $nav['description'] ?? $nav['name'],
                        'url' => $nav['url']
                    ];
                endforeach;
                echo json_encode($itemElements, JSON_UNESCAPED_UNICODE);
                ?>]
        }
    }
    </script>
    <?php endforeach; ?>
    <?php endif; ?>

    <!-- 增强的WebApplication结构化数据 -->
    <script type="application/ld+json">
    {
        "@context": "https://schema.org",
        "@type": "WebApplication",
        "name": "<?php echo htmlspecialchars($siteTitle); ?>",
        "description": "<?php echo htmlspecialchars($siteDescription); ?>",
        "url": "<?php echo SITE_URL; ?>",
        "applicationCategory": "Productivity",
        "operatingSystem": "All",
        "browserRequirements": "Requires JavaScript. Requires HTML5.",
        "softwareVersion": "2.0",
        "author": {
            "@type": "Organization",
            "@id": "<?php echo SITE_URL; ?>#organization",
            "name": "<?php echo htmlspecialchars($siteTitle); ?>"
        },
        "publisher": {
            "@type": "Organization",
            "@id": "<?php echo SITE_URL; ?>#organization",
            "name": "<?php echo htmlspecialchars($siteTitle); ?>"
        },
        "offers": {
            "@type": "Offer",
            "price": "0",
            "priceCurrency": "CNY",
            "availability": "https://schema.org/InStock",
            "priceValidUntil": "2025-12-31"
        },
        "aggregateRating": {
            "@type": "AggregateRating",
            "ratingValue": "4.8",
            "ratingCount": "1000",
            "bestRating": "5",
            "worstRating": "1",
            "itemReviewed": {
                "@type": "WebSite",
                "@id": "<?php echo SITE_URL; ?>#website",
                "name": "<?php echo htmlspecialchars($siteTitle); ?>"
            }
        },
        "featureList": [
            "免费设计资源导航",
            "免版权图片推荐",
            "开发工具集合",
            "字体资源库",
            "图标素材网站",
            "在线工具推荐"
        ]
    }
    </script>

    <!-- Sitemap 引用 -->
    <link rel="sitemap" type="application/xml" href="<?php echo SITE_URL; ?>sitemap.xml">

    <script>
    var _hmt = _hmt || [];
    (function() {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?67413f65b89d1662ecc4817afe9edfc8";
    var s = document.getElementsByTagName("script")[0]; 
    s.parentNode.insertBefore(hm, s);
    })();
    </script>

</head>
<body>
    <!-- 主容器 -->
    <div class="main-container">
        <!-- ilovefree 顶部搜索区域 -->
        <header class="dingbu">
            <!-- Logo区域 -->
            <div class="logo-area">
                <h1>I Love Free</h1>
                <p> 产品/设计师/独立开发者的资源网站导航 </p>
            </div>

            <!-- 搜索区域 -->
            <div class="search-container">
                <div class="search-wrapper">
                    <form id="searchForm" class="search-form" action="https://www.baidu.com/s" method="get" target="_blank">
                        <!-- 搜索引擎选择器 -->
                        <div class="search-select">
                            <button type="button" class="search-engine-toggle" id="searchEngineToggle">
                                
                                <span id="currentSearchEngine">百度</span>
                                <i class="fas fa-chevron-down"></i>
                            </button>

                            <div class="search-engine-dropdown" id="searchEngineDropdown">
                                <div class="search-engine-options">
                                    <div class="search-engine-option active" data-engine="baidu" data-action="https://www.baidu.com/s" data-name="wd">
                                        <span>百度</span>
                                    </div>
                                    <div class="search-engine-option" data-engine="sogou" data-action="https://www.sogou.com/web" data-name="query">
                                        <span>搜狗</span>
                                    </div>
                                    <div class="search-engine-option" data-engine="bing" data-action="https://www.bing.com/search" data-name="q">
                                        <span>必应</span>
                                    </div>
                                    <div class="search-engine-option" data-engine="360" data-action="https://www.so.com/s" data-name="q">
                                        <span>360搜索</span>
                                    </div>
                                    <div class="search-engine-option" data-engine="google" data-action="https://www.google.com/search" data-name="q">
                                        <span>Google</span>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- 搜索输入框 -->
                        <div class="search-input-group">
                            <input type="text"
                                   name="wd"
                                   id="searchInput"
                                   class="search-input"
                                   placeholder="请您输入您要搜索的内容..."
                                   autocomplete="off">
                             <!-- 搜索按钮 -->
                        <button type="button" class="search-button" onclick="window.ilovefreeSearch.performSearch(); return false;">
                            <i class="fas fa-search"></i>
                        </button>
                        </div>

                        
                    </form>
                </div>
            </div>

          </header>

        <!-- SEO面��屑导航 -->
        <nav class="breadcrumb-container" aria-label="面包屑导航" style="display: none; padding: 15px 0; max-width: 1200px; margin: 0 auto; font-size: 14px; color: #666;">
            <ol itemscope itemtype="https://schema.org/BreadcrumbList" class="breadcrumb-list" style="display: flex; align-items: center; list-style: none; padding: 0; margin: 0; gap: 8px;">
                <li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem" class="breadcrumb-item">
                    <a href="<?php echo SITE_URL; ?>" itemprop="item" itemscope itemtype="https://schema.org/WebPage" itemid="<?php echo SITE_URL; ?>" style="color: #667eea; text-decoration: none; transition: color 0.3s ease; font-weight: 500;">
                        <span itemprop="name">首页</span>
                    </a>
                    <meta itemprop="position" content="1">
                </li>
                <li class="breadcrumb-separator" style="color: #999; margin: 0 4px;">›</li>
                <li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem" class="breadcrumb-item">
                    <span itemprop="name" style="color: #333; font-weight: 500;">免费素材导航</span>
                    <meta itemprop="position" content="2">
                </li>
                <?php
                // 如果URL有分类锚点，添加到面包屑
                $currentUrl = $_SERVER['REQUEST_URI'] ?? '';
                if (strpos($currentUrl, '#') !== false) {
                    $anchor = substr($currentUrl, strpos($currentUrl, '#') + 1);
                    $categoryName = '';

                    // 查找对应的分类名称
                    foreach ($categories as $cat) {
                        $catAnchor = strtolower(str_replace([' ', '&', ' ', '，'], '-', $cat['name']));
                        if ($catAnchor === urldecode($anchor)) {
                            $categoryName = $cat['name'];
                            break;
                        }
                    }

                    if ($categoryName) {
                        echo '<li class="breadcrumb-separator" style="color: #999; margin: 0 4px;">›</li>';
                        echo '<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem" class="breadcrumb-item">';
                        echo '<span itemprop="name" style="color: #333; font-weight: 500;">' . htmlspecialchars($categoryName) . '</span>';
                        echo '<meta itemprop="position" content="3">';
                        echo '</li>';
                    }
                }
                ?>
            </ol>
        </nav>

        <!-- 主要内容区域 -->
        <main class="main-content">
            <!-- 常用导航区域 -->
            <?php if (!empty($favoriteNavigations)): ?>
                <div class="favorite-navigation" style="margin-top: 40px;">
                    <div class="favorite-nav-grid">
                        <?php foreach ($favoriteNavigations as $nav): ?>
                            <div class="favorite-nav-item" data-nav-id="<?php echo $nav['id']; ?>">
                                <a href="<?php echo htmlspecialchars($nav['url']); ?>"
                                   class="favorite-nav-link"
                                   target="_blank"
                                   rel="<?php echo getLinkRelAttribute($nav['url']); ?>"
                                   title="<?php echo htmlspecialchars($nav['description'] ?? $nav['name']); ?>">
                                    <div class="favorite-nav-icon <?php echo ($nav['icon_type'] !== 'class') ? 'has-image' : ''; ?>">
                                        <?php if ($nav['icon_type'] === 'class'): ?>

                                        <?php else: ?>
                                            <img src="<?php echo htmlspecialchars($nav['icon']); ?>"
                                                 alt="<?php echo htmlspecialchars($nav['name'] . ' - ' . ($nav['description'] ?? $category['name'] . '网站')); ?>"
                                                 title="<?php echo htmlspecialchars($nav['description'] ?? $nav['name'] . ' - ' . $category['name'] . '分类网站'); ?>"
                                                 loading="lazy"
                                                 width="32" height="32"
                                                 onerror="this.style.display='none';">

                                        <?php endif; ?>
                                    </div>
                                    <span class="favorite-nav-name"><?php echo htmlspecialchars($nav['name']); ?></span>
                                </a>
                            </div>
                        <?php endforeach; ?>
                    </div>
                </div>
            <?php endif; ?>
            
            <!-- 导航区域 -->
            <section class="navigation-section">
                <?php if (!empty($categories)): ?>
                    <!-- 所有分类和导航展示 -->
                    <div class="nav-all-container">
                        <?php foreach ($categories as $category): ?>
                            <div class="category-section" data-category-id="<?php echo $category['id']; ?>" data-display-style="<?php echo htmlspecialchars($category['display_style'] ?? 'STYLE_1'); ?>">
                                <!-- 分类标题 -->
                                <div class="category-header">
                                    <div class="category-title">
                                            <?php if (isset($category['icon_type']) && $category['icon_type'] === 'url'): ?>
                                                <img src="<?php echo htmlspecialchars($category['icon']); ?>"
                                                     alt="<?php echo htmlspecialchars($category['name'] . '分类图标 - 免费资源导航'); ?>"
                                                     title="<?php echo htmlspecialchars($category['name'] . '分类 - 免费设计资源导航'); ?>"
                                                     style="width: 24px; height: 24px; object-fit: contain;"
                                                     loading="lazy"
                                                     onerror="this.style.display='none'; this.nextElementSibling.style.display='inline';">
                                                <i class="fas fa-folder fallback-icon"></i>
                                            <?php else: ?>
                                                <i class="<?php echo $category['icon']; ?>"></i>
                                            <?php endif; ?>
                                        <h2 class="category-name"
    itemscope itemtype="https://schema.org/Thing"
    itemprop="name"><?php echo htmlspecialchars($category['name']); ?></h2>
<meta itemprop="description" content="收录优质<?php echo htmlspecialchars($category['name']); ?>网站">
<meta itemprop="url" content="<?php echo SITE_URL; ?>#category-<?php echo $category['id']; ?>">
                                    </div>

                                                                  <!-- 标签显示区域 - 移到category-header内部 -->
                                        <div class="tags-container" id="category-<?php echo $category['id']; ?>">
                                            <?php if (!empty($tags[$category['id']])): ?>
                                                <!-- 添加"推荐"标签 -->
                                                <?php
                                                // 先计算推荐标签信息以便在按钮中使用
                                                $recommendCountForBtn = 0;
                                                $recommendTagIdForBtn = 0;
                                                foreach ($tags[$category['id']] as $tag) {
                                                    if ($tag['name_cn'] === '推荐') {
                                                        $recommendTagIdForBtn = $tag['id'];
                                                        break;
                                                    }
                                                }

                                                if ($recommendTagIdForBtn > 0) {
                                                    foreach ($navigations[$category['id']] as $nav) {
                                                        if (!empty($nav['tag_ids']) && is_array($nav['tag_ids'])) {
                                                            if (in_array($recommendTagIdForBtn, $nav['tag_ids'])) {
                                                                $recommendCountForBtn++;
                                                            }
                                                        }
                                                    }
                                                }

                                                // 只有当推荐标签确实存在且有导航项时才设置为激活状态
                                                $recommendActive = ($recommendTagIdForBtn > 0 && $recommendCountForBtn > 0) ? 'active' : '';
                                                ?>
                                                <button class="tag-btn <?php echo $recommendActive; ?>" data-tag-id="<?php echo $recommendTagIdForBtn; ?>" data-tag-filter="推荐" data-category-id="<?php echo $category['id']; ?>">
                                                    推荐
                                                    <span class="tag-count"><?php echo $recommendCountForBtn; ?></span>
                                                </button>

                                                <?php
                                                // 过滤掉名为"全部"和"推荐"的标签（推荐标签已手动添加）
                                                $filteredTags = array_filter($tags[$category['id']], function($tag) {
                                                    return trim($tag['name_cn']) !== '全部' && trim($tag['name_cn']) !== '推荐';
                                                });
                                                ?>
                                                <?php foreach ($filteredTags as $tag): ?>
                                                    <?php
                                                    // 计算该标签下的导航数量
                                                    $tagNavCount = 0;
                                                    if (!empty($navigations[$category['id']])) {
                                                        foreach ($navigations[$category['id']] as $nav) {
                                                            if (!empty($nav['tag_ids']) && is_array($nav['tag_ids'])) {
                                                                if (in_array($tag['id'], $nav['tag_ids'])) {
                                                                    $tagNavCount++;
                                                                }
                                                            }
                                                        }
                                                    }
                                                    ?>
                                                    <button class="tag-btn" data-tag-id="<?php echo $tag['id']; ?>" data-tag-filter="<?php echo htmlspecialchars($tag['name_cn']); ?>" data-category-id="<?php echo $category['id']; ?>">
                                                        <?php echo htmlspecialchars($tag['name_cn']); ?>
                                                        <span class="tag-count"><?php echo $tagNavCount; ?></span>
                                                    </button>
                                                <?php endforeach; ?>
                                            <?php endif; ?>
                                        </div>

                                    <div class="category-line"></div>
                                </div>

                                <!-- 该分类下的导航项目 -->
                                <?php
                                // 计算推荐标签信息（移到导航循环外面）
                                $recommendCount = 0;
                                $recommendTagId = 0;
                                foreach ($tags[$category['id']] as $tag) {
                                    if ($tag['name_cn'] === '推荐') {
                                        $recommendTagId = $tag['id'];
                                        break;
                                    }
                                }

                                if ($recommendTagId > 0) {
                                    foreach ($navigations[$category['id']] as $nav) {
                                        if (!empty($nav['tag_ids']) && is_array($nav['tag_ids'])) {
                                            if (in_array($recommendTagId, $nav['tag_ids'])) {
                                                $recommendCount++;
                                            }
                                        }
                                    }
                                }

                                if (!empty($navigations[$category['id']])): ?>
                                    <?php
                                    // 获取当前分类的CSS样式类
                                    $navGridClass = 'nav-grid ' . getDisplayStyleClass($category['display_style'] ?? 'STYLE_1');
                                    ?>
                                    <div class="<?php echo $navGridClass; ?>" id="nav-grid-<?php echo $category['id']; ?>">
                                        <?php foreach ($navigations[$category['id']] as $nav): ?>
                                            <?php
                                            // 获取导航的标签ID数组
                                            $navTagIds = isset($nav['tag_ids']) ? json_encode($nav['tag_ids']) : '[]';

                                            // 构建data-tag-filters属性
                                            $tagFilters = [];
                                            if (!empty($nav['tag_ids']) && is_array($nav['tag_ids'])) {
                                                foreach ($nav['tag_ids'] as $tagId) {
                                                    if (!empty($tags[$category['id']])) {
                                                        foreach ($tags[$category['id']] as $tag) {
                                                            if ($tag['id'] == $tagId) {
                                                                $tagFilters[] = htmlspecialchars($tag['name_cn']);
                                                                break;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            // 只有当导航真正包含推荐标签时才添加"推荐"标签
                                            if ($recommendTagId > 0 && !empty($nav['tag_ids']) && is_array($nav['tag_ids']) && in_array($recommendTagId, $nav['tag_ids'])) {
                                                $tagFilters[] = '推荐';
                                            }
                                            $tagFiltersString = implode(',', array_unique($tagFilters));

                                            // 判断是否需要初始隐藏这个导航项
                                            $initialHidden = '';
                                            if ($recommendTagId > 0 && $recommendCount > 0) {
                                                // 如果该分类有推荐标签且有推荐内容，则隐藏不包含推荐标签的导航项
                                                if (!in_array('推荐', array_unique($tagFilters))) {
                                                    $initialHidden = ' style="display: none;"';
                                                }
                                            }
                                            ?>
                                            <a href="<?php echo htmlspecialchars($nav['url']); ?>"
                                               class="nav-link"
                                               target="_blank"
                                               rel="<?php echo getLinkRelAttribute($nav['url']); ?>"
                                               title="<?php echo htmlspecialchars($nav['description'] ?? $nav['name']); ?>"
                                               data-nav-id="<?php echo $nav['id']; ?>"
                                               data-category-id="<?php echo $category['id']; ?>"
                                               data-tag-ids='<?php echo $navTagIds; ?>'
                                               data-tag-filters="<?php echo $tagFiltersString; ?>"
                                               <?php echo $initialHidden; ?>>
                                                <?php
                                                // 样式四不显示图标，其他样式显示图标
                                                if ($category['display_style'] !== 'STYLE_4'):
                                                ?>
                                                <div class="nav-icon-wrapper">
                                                    <?php if ($nav['icon_type'] === 'class'): ?>

                                                    <?php else: ?>
                                                        <img src="<?php echo htmlspecialchars($nav['icon']); ?>"
                                                             alt="<?php echo htmlspecialchars($nav['name'] . ' - ' . ($nav['description'] ?? $category['name'] . '网站')); ?>"
                                                             title="<?php echo htmlspecialchars($nav['description'] ?? $nav['name'] . ' - ' . $category['name'] . '分类网站'); ?>"
                                                             class="nav-icon nav-icon-img"
                                                             loading="lazy"
                                                             width="32" height="32"
                                                             onerror="this.style.display='none';">

                                                    <?php endif; ?>
                                                </div>
                                                <?php endif; ?>
                                                <div class="nav-content">
                                                    <h3 class="nav-title"><?php echo htmlspecialchars($nav['name']); ?></h3>
                                                    <?php if (!empty($nav['description'])): ?>
                                                        <p class="nav-description"><?php echo htmlspecialchars($nav['description']); ?></p>
                                                    <?php endif; ?>

                                                    <!-- 导航链接项标签显示 -->
                                                    <?php if (!empty($nav['tag_ids']) && is_array($nav['tag_ids'])): ?>
                                                        <div class="nav-tags">
                                                            <?php
                                                            $navTags = [];
                                                            foreach ($nav['tag_ids'] as $tagId) {
                                                                if (!empty($tags[$category['id']])) {
                                                                    foreach ($tags[$category['id']] as $tag) {
                                                                        if ($tag['id'] == $tagId) {
                                                                            $navTags[] = $tag;
                                                                            break;
                                                                        }
                                                                    }
                                                                }
                                                            }

                                                            if (!empty($navTags)): ?>
                                                                <?php
                                                                // 定义七种淡色：绿、青、蓝、紫、天蓝、抹茶、天青
                                                                $tagColors = [
                                                                    'rgba(34, 197, 94, 0.6)',    // 绿 - 淡绿色
                                                                    'rgba(6, 182, 212, 0.6)',     // 青 - 淡青色
                                                                    'rgba(59, 130, 246, 0.6)',    // 蓝 - 淡蓝色
                                                                    'rgba(147, 51, 234, 0.6)',    // 紫 - 淡紫色
                                                                    'rgba(125, 211, 252, 0.6)',   // 天蓝 - 淡天蓝色
                                                                    'rgba(167, 243, 208, 0.6)',   // 抹茶 - 淡抹茶色
                                                                    'rgba(224, 242, 254, 0.6)'    // 天青 - 淡天青色
                                                                ];
                                                                ?>
                                                                <?php foreach ($navTags as $index => $tag): ?>
                                                                    <?php
                                                                    // 根据标签ID计算颜色索引，确保同一个标签颜色一致
                                                                    $colorIndex = $tag['id'] % 7;
                                                                    $tagColor = $tagColors[$colorIndex];
                                                                    ?>
                                                                    <span class="nav-tag" style="color: <?php echo $tagColor; ?>;"><?php echo htmlspecialchars($tag['name_cn']); ?></span>
                                                                <?php endforeach; ?>
                                                            <?php endif; ?>
                                                        </div>
                                                    <?php endif; ?>

                                                                                    <!-- 分类标签显示已禁用 - 仅后台管理使用多分类功能 -->
                            <?php
                            // 多分类功能保留在后台，前台不显示分类标签
                            // $navCategories = $db->getNavigationCategoriesInfo($nav['id']);
                            ?>
                                                </div>
                                                </a>
                                        <?php endforeach; ?>
                                    </div>
                                <?php else: ?>
                                    <div class="empty-state">
                                        <div class="empty-icon">
                                            <svg width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
                                                <circle cx="12" cy="12" r="10"></circle>
                                                <circle cx="12" cy="10" r="3"></circle>
                                                <path d="M7 20.662V19a2 2 0 0 1 2-2h6a2 2 0 0 1 2 2v1.662"></path>
                                            </svg>
                                        </div>
                                        <h3 class="empty-title">暂无导航链接</h3>
                                        <p class="empty-description">该分类下还没有添加任何导航链接</p>
                                    </div>
                                <?php endif; ?>
                            </div>
                        <?php endforeach; ?>
                    </div>
                <?php else: ?>
                    <div class="empty-state-global">
                        <div class="empty-icon">
                            <svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
                                <circle cx="12" cy="12" r="10"></circle>
                                <polygon points="10,8 16,12 10,16 10,8"></polygon>
                            </svg>
                        </div>
                        <h3 class="empty-title">暂无导航分类</h3>
                        <p class="empty-description">系统还没有配置任何导航分类，请联系管理员添加内容</p>
                    </div>
                <?php endif; ?>
            </section>
        </main>

        <!-- 粘性侧边��航栏 - 独立组件，不影响现有页面 -->
        <?php if (!empty($categories)): ?>
            <div class="sticky-nav-container">
                <div class="sticky-nav__wrapper">
                    <div class="sticky-nav__progress"></div>
                    <nav class="sticky-nav__nav">
                        <ul class="sticky-nav__list">
                            <?php foreach ($categories as $category): ?>
                                <li class="sticky-nav__item">
                                    <a href="#category-<?php echo $category['id']; ?>"
                                       class="sticky-nav__link"
                                       data-tooltip="<?php echo htmlspecialchars($category['name']); ?>"
                                       title="<?php echo htmlspecialchars($category['name']); ?>">
                                        <?php
                                        // 优先使用short_name字段，如果没有则使用分类名称的简短版本
                                        if (!empty($category['short_name'])) {
                                            echo htmlspecialchars($category['short_name']);
                                        } else {
                                            // 根据分类ID显示对应的中文名称
                                            $categoryLabels = array(
                                                2 => '图库',   // 免版权图库
                                                3 => '背景',    // 在线生成背景
                                                4 => '纹理',   // 平铺纹理
                                                5 => '字体',  // 免版权字体
                                                6 => '音效',   // 免版权音效
                                                7 => '音乐', // 免版权音乐
                                                8 => '视频', // 免版权视频
                                                9 => '图标',  // 免版权图标
                                                10 => '工具', // 在线工具
                                                11 => '学习', // 学习
                                                12 => '新鲜'   // 新鲜
                                            );
                                            echo $categoryLabels[$category['id']] ?? '分类' . $category['id'];
                                        }
                                        ?>
                                    </a>
                                </li>
                            <?php endforeach; ?>
                        </ul>
                    </nav>
                    <div class="sticky-nav__back-to-top">
                        <a href="#"
                           class="sticky-nav__link"
                           data-tooltip="返回顶部"
                           title="返回顶部"
                           onclick="StickyNav.scrollToTop(); return false;">
                            <i class="fas fa-arrow-up"></i>
                        </a>
                    </div>
                </div>
            </div>
        <?php endif; ?>
        
        <!-- 底部区域 -->
        <footer class="footer">
            <div class="footer-content">
                <div class="footer-main">
                    <p class="copyright" style="text-align: center !important; width: 100%; display: block !important;">
                        <a href="https://www.ilovefree.com/" target="_blank" rel="<?php echo getLinkRelAttribute('https://www.ilovefree.com/'); ?>" style="color: inherit; text-decoration: none;">
                            <?php if (!empty($settings['footer_copyright'])): ?>
                                <?php echo htmlspecialchars($settings['footer_copyright']); ?>
                            <?php else: ?>
                                &copy; <?php echo date('Y'); ?> <?php echo $siteTitle; ?> ilovefree.com. 保留所有权利
                            <?php endif; ?>
                        </a>
                    </p>
                    <div class="footer-info">
                        <?php if (!empty($settings['footer_icp_number'])): ?>
                            <a href="https://beian.miit.gov.cn/" target="_blank" class="icp-number"><svg t="1757663899448" class="beian-icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5697" width="24" height="24"><path d="M778.24 163.84c-76.8-40.96-165.888-61.44-269.312-61.44s-192.512 20.48-269.312 61.44h-133.12l23.552 337.92c8.192 113.664 67.584 217.088 162.816 280.576l215.04 144.384 215.04-144.384c96.256-63.488 155.648-166.912 163.84-280.576l23.552-337.92H778.24z m47.104 333.824c-7.168 94.208-56.32 181.248-135.168 233.472l-181.248 120.832L327.68 731.136c-78.848-53.248-129.024-139.264-135.168-233.472L173.056 225.28h136.192v-26.624c58.368-23.552 124.928-34.816 199.68-34.816s141.312 12.288 199.68 34.816V225.28H844.8l-19.456 272.384z" fill="#0649D0" p-id="5698"></path><path d="M685.056 328.704v-46.08H455.68c2.048-4.096 6.144-9.216 11.264-15.36 5.12-7.168 9.216-12.288 11.264-15.36L419.84 240.64c-31.744 46.08-75.776 87.04-133.12 123.904 4.096 4.096 10.24 11.264 18.432 21.504l17.408 17.408c23.552-15.36 45.056-31.744 63.488-50.176 26.624 25.6 49.152 43.008 67.584 51.2-46.08 15.36-104.448 27.648-175.104 35.84 2.048 5.12 6.144 13.312 9.216 24.576 4.096 11.264 6.144 19.456 7.168 24.576l39.936-7.168v218.112H389.12V680.96h238.592v19.456h54.272V481.28H348.16c60.416-12.288 114.688-27.648 163.84-46.08 49.152 19.456 118.784 34.816 210.944 46.08 5.12-17.408 10.24-34.816 17.408-51.2-62.464-4.096-116.736-12.288-161.792-24.576 38.912-20.48 74.752-46.08 106.496-76.8z m-150.528 194.56h94.208v41.984h-94.208v-41.984z m0 78.848h94.208v41.984h-94.208v-41.984z m-144.384-78.848h94.208v41.984H390.144v-41.984z m0 78.848h94.208v41.984H390.144v-41.984zM424.96 326.656h182.272c-26.624 22.528-57.344 41.984-94.208 57.344-31.744-15.36-61.44-34.816-88.064-57.344z" fill="#0649D0" p-id="5699"></path></svg> ICP备案号：<?php echo htmlspecialchars($settings['footer_icp_number']); ?></a>
                        <?php endif; ?>
                        <?php if (!empty($settings['footer_beian_number'])): ?>
                            <a href="http://www.beian.gov.cn/portal/index.do" target="_blank" class="beian-number"><svg t="1757674978700" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns=" `http://www.w3.org/2000/svg` " p-id="41535" width="24" height="24"><path d="M511.9 960.2l-18.9-7.3C195.8 838 161.5 684.3 161.5 578.6V177.5l54.2 1.9c180.2 7.8 257.5-72.9 258.2-73.8l38.2-41.8 38.6 42.2c0.2 0.2 82.7 80.4 257.6 73.3l54.3-1.9v401.1c0 105.7-34.3 259.4-331.6 374.4l-19.1 7.3zM217.5 235.6v343.1c0 89 30.5 219.1 294.4 321.4 263.9-102.4 294.4-232.5 294.4-321.4V235.6c-6 0.2-12 0.3-17.9 0.3-173.4 0-260.5-74-276.5-89.1-18.7 18.1-109 93.6-294.4 88.8z m0 0" fill="#333333" p-id="41536"></path><path d="M673.4 686.6l-161.5-85-161.5 84.9 30.8-179.8-130.5-127.2 180.5-26.3L512 189.6l80.7 163.6 180.6 26.3-130.7 127.2 30.8 179.9zM511.9 538.4l87 45.6-16.6-96.9 70.4-68.6-97.3-14.1-43.4-88.1-43.5 88.1-97.2 14.1 70.4 68.6L425 584l86.9-45.6zM357.5 718.2h308.8v56.1H357.5v-56.1z m0 0" fill="#2468F2" p-id="41537"></path></svg> 网安备案号：<?php echo htmlspecialchars($settings['footer_beian_number']); ?></a>
                        <?php endif; ?>
                        <?php if (!empty($settings['footer_other_info'])): ?>
                            <span class="other-info"><?php echo $settings['footer_other_info']; ?></span>
                        <?php endif; ?>
                    </div>
                </div>
                 </div>
        </footer>
        
        <!-- 自定义底部脚本代码 -->
        <?php if (!empty($settings['footer_script_code'])): ?>
            <?php echo $settings['footer_script_code']; ?>
        <?php endif; ?>
    </div>
    
    <!-- 加载状态 -->
    <div id="loadingOverlay" class="loading-overlay">
        <div class="loading-spinner">
            <div class="spinner-ring">
                <div></div>
                <div></div>
                <div></div>
                <div></div>
            </div>
            <p class="loading-text">加载中...</p>
        </div>
    </div>
    
    <!-- JavaScript配置扩展 -->
    <script>
        // 扩展配置信息
        Object.assign(window.CONFIG, {
            baseUrl: '<?php echo BASE_URL; ?>',
            siteUrl: '<?php echo SITE_URL; ?>',
            assetsUrl: '<?php echo asset(""); ?>',
            // API URL已经在config.js中设置为不带.php后缀
        });
        
        // 导航数据
        window.NAV_DATA = {
            categories: <?php echo json_encode($categories, JSON_UNESCAPED_UNICODE); ?>,
            navigations: <?php echo json_encode($navigations, JSON_UNESCAPED_UNICODE); ?>,
            tags: <?php echo json_encode($tags, JSON_UNESCAPED_UNICODE); ?>
        };

        // 记录配置已加载
        window.CONFIG.log('info', '导航系统已加载，配置完成');
    </script>

  
    <!-- ilovefree 搜索功能 -->
    <script src="<?php echo asset('js/ilovefree-search.js'); ?>"></script>

    <!-- ilovefree PHP项目样式迁移JavaScript系统 -->
    <script src="<?php echo asset('js/php-ilovefree-migration.js'); ?>"></script>
    <script src="<?php echo asset('js/enhanced-interactions.js'); ?>"></script>

    <!-- 粘性导航栏JavaScript -->
    <script src="<?php echo asset('js/sticky-nav.js'); ?>"></script>

    <script src="<?php echo asset('js/app.js'); ?>"></script>
</body>
</html>